package edu.gatech.spacetraderteam3.view;

import java.awt.Dimension;
import java.awt.Graphics2D;
import java.util.ArrayList;
import java.util.List;

/**
 * Represents the view of the Space Trader Game
 * @author Alexander Ikonomidis
 * @version 1.0
 */
public class View {
    
	/**
	 * A list of SGGWindows that pop up in the view
	 */
	protected static List<SGGWindow> PopupWindows = new ArrayList<SGGWindow>();
    
	/**
	 * The dimension of the view
	 */
	protected Dimension dimension;
	
	/**
	 * Integer vals that dictate where and how big the view is
	 * on the screen
	 */
    protected int wid, hei, centerX, centerY;

    /**
     * Reinstates the dimensions of this view
     */
    protected View() {
        dimension = new Dimension(1, 1);
    }

    /**
     * Repaints the current view
     */
    protected void repaint() {
        SGGWM.requestRepaint();
    }

    /**
     * Paints the view onto the screen
     * @param g2
     */
    public void paint(Graphics2D g2) {
        if (!dimension.equals(SGGWM.getWindowSize())) {
            onWindowResize();
        }
    }

    /**
     * Resizes the view
     */
    public void onWindowResize() {
        dimension = SGGWM.getWindowSize();
        wid = (int) dimension.getWidth();
        hei = (int) dimension.getHeight();
        centerX = wid / 2;
        centerY = hei / 2;
    }

    /**
     * Hides all pop up windows in this view
     */
    protected void hidePopups() {
        for (SGGWindow window : PopupWindows) {
            window.setVisible(false);
        }
    }

    /**
     * Toggles a particular window to open and closed
     * @param window
     */
    protected void togglePopup(SGGWindow window) {
        boolean v = window.isVisible();
        hidePopups();
        window.setVisible(!v);
    }

    /**
     * @return The string representation of a view
     */
    public String toString() {
        return "This is the view.";
    }
}
